package com.kehao.leetcode.basic.array;

/**
 *
 * 有效的数独
 * https://leetcode-cn.com/leetbook/read/top-interview-questions-easy/x2f9gg/
 *
 */
public class ArraySolution10 {

    public boolean isValidSudoku(char[][] board) {
        boolean[][] line = new boolean[board.length][board.length];
        boolean[][] column = new boolean[board.length][board.length];
        boolean[][] cell = new boolean[board.length][board.length];

        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board.length; j++) {
                if(board[i][j]=='.')
                    continue;
                int num = board[i][j]-'0'-1;
                int index = i/3*3+j/3;
                if(line[i][num]==true||column[j][num]==true||cell[index][num]==true){
                    return false;
                }
                line[i][num]=column[j][num]=cell[index][num]=true;
            }
        }
        return true;
    }
}
